<h1>
  Authors by category (<?php echo $category->getName() ?>)
</h1>

<div class="alternate_table">
  <table cellpadding="0" cellspacing="0" style="width: 100%">
    <tbody>
      <?php foreach($pager->getResults() as $i => $author): ?>
        <tr class="<?php echo ($i%2==0)?'even':'odd' ?>">
          <td>
            <p>
              <a href="<?php echo url_for('author_show', $author) ?>">
                <?php echo $author->getName() ?>
              </a>
              <br />
              <?php if($author->getContent()): ?>
                <a style="font-size: smaller;cursor: pointer" class="desc_link show" rel="<?php echo $i ?>">
                  (Show description)
                </a>
              <?php endif ?>
              <div class="content <?php echo $i ?>" style="display: none">
                <?php $trimmed_content = $author->getTrimmedContent() ?>
                <p id="<?php echo $i ?>" class="trimmed">
                  <?php echo nl2br($trimmed_content['value']) ?>
                  <?php if($trimmed_content['more'] == true): ?>
                    <br />
                    <a paragraph="<?php echo $i ?>" class="more">
                      More ...
                    </a>
                  <?php endif ?>
                </p>

                <p rel="<?php echo $i ?>" class="full" style="display: none">
                  <?php echo nl2br($author->getContent()) ?>
                  <br />
                  <a paragraph="<?php echo $i ?>" class="less">
                    Less ...
                  </a>
                </p>
              </div>
            </p>
          </td>
          <td class="right_sided">
            <?php if($sf_user->isAuthenticated()): ?>
              <?php if($author->isBookmark($sf_user->getAttribute('user_id', null, 'sfGuardSecurityUser'))): ?>
                <a class="remove_book" title="Remove from bookmarks" href="<?php echo url_for('profile/removeAuthorBookmark?author_id='.$author->getId()) ?>"></a>
              <?php else: ?>
                <a class="add_book" title="Add to bookmarks" href="<?php echo url_for('profile/addAuthorBookmark?author_id='.$author->getId()) ?>"></a>
              <?php endif ?>
            <?php endif ?>
          </td>
        </tr>
      <?php endforeach ?>
    </tbody>

    <tfoot>
      <tr>
        <td class="bottom_row">
          <?php if ($pager->haveToPaginate()): ?>
            <div class="pagination">
              <a href="<?php echo url_for('@author_show_by_category?page=1&slug='.$category->getSlug()) ?>">
                << First
              </a>

              <a href="<?php echo url_for('@author_show_by_category?page='.$pager->getPreviousPage().'&slug='.$category->getSlug()) ?>">
                < Previous
              </a>

              <?php if($pager->getPage() > 3): ?> ... <?php endif ?>

              <?php foreach ($pager->getLinks() as $page): ?>
                <?php if ($page == $pager->getPage()): ?>
                  <?php echo $page ?>
                <?php else: ?>
                  <a href="<?php echo url_for('@author_show_by_category?page='.$page.'&slug='.$category->getSlug()) ?>">
                    <?php echo $page ?>
                  </a>
                <?php endif ?>

              <?php endforeach ?>

              <?php if($pager->getLastPage() - $pager->getPage() > 3): ?> ... <?php endif ?>

              <a href="<?php echo url_for('@author_show_by_category?page='.$pager->getNextPage().'&slug='.$category->getSlug()) ?>">
                Next >
              </a>

              <a href="<?php echo url_for('author_show_by_category', $category).'?page='.$pager->getLastPage() ?>">
                Last >>
              </a>
            </div>
          <?php endif; ?>
        </td>
      </tr>

      <tr>
        <td>
          <div class="pagination_desc">
            <strong><?php echo count($pager) ?></strong> authors
            <?php if ($pager->haveToPaginate()): ?>
              - page <strong><?php echo $pager->getPage() ?> of <?php echo $pager->getLastPage() ?></strong>
            <?php endif; ?>
          </div>
        </td>
      </tr>

    </tfoot>
  </table>
</div>

<script type="text/javascript">
  $(document).ready(function(){
    $('.more').click(function(){
      var paragraph = $(this).attr('paragraph');
      $('p#'+paragraph+'.trimmed').slideUp(400, function(){
        $('p[rel="'+paragraph+'"]').slideDown();
      });
    });

    $('.less').click(function(){
      var paragraph = $(this).attr('paragraph');
      $('p[rel="'+paragraph+'"]').slideUp(400, function(){
        $('p#'+paragraph+'.trimmed').slideDown();
      });
    });

    $('.desc_link').click(function(){
      var rel = $(this).attr('rel');
      $('.content.'+rel).slideToggle();
      var text = $(this).text() == '(Hide description)' ? '(Show description)' : '(Hide description)';
      $(this).text(text);
    })
  });
</script>
